// SPDX-License-Identifier: Some Identifier
pragma solidity ^0.8.10;
// A simple contract with getter and setter functions
contract GetterSetterContract {
string value = “Some Value”;
function getValue() public view returns(string memory) {
return value;
}
function setValue(string memory newValue) public {
value = newValue;
}
}
In a simple Solidity program, you can find how the value is allocated
with the setValue function and then retrieved later using a getValue
function.
Please do not worry about the keyword “memory”. We will cover that
later in this chapter.
2.5.8.3 Return Values
A function can have one or more optional return statements as the
last line. We already know how the getter function returns a value,
whereas a setter does not. Now, let’s improve the program further to
retrieve multiple values in the same function. Refer to the following
code:
// SPDX-License-Identifier: Some Identifier
pragma solidity ^0.8.10;
// A simple contract with getter and setter functions and
multiple values in return statement
contract GetterSetterContract {
string value1 = “Some Value 1”;
string value2 = “Some Value 2”;